<template>
  <div class="ts-forgot">
    <ts-header title="忘记密码" back></ts-header>
    <form-input :formData="formData"
                btnText="确认重置" :codeSeconds="codeSeconds" :codeInterval="codeInterval"
                @submit="updPwd"></form-input>
  </div>
</template>

<script>
  import FormInput from '../../components/module/FormInput.vue'
  import {FORGOT} from '../../assets/js/api'

  export default {
    components: {FormInput},
    name: 'forgot',
    data() {
      return {
        formData: {
          tel: null,
          code: null,
          password: '',
          rePassword: '',
          type: 3
        },
        codeSeconds: 60,
        codeInterval: null
      }
    },
    created() {
      let {tel} = this.$store.state.currentUser;
      this.formData.tel = tel;
    },
    methods: {
      async updPwd() {
        delete this.formData.type;
        let json = await this.$http.post(FORGOT, this.formData, {show: true});
        this.formData.type = 3;
        let {result, data} = json;
        if (result === 1) {
          this.$toast({message: data})
          this.$router.goBack()
//          this.$router.push({name: 'login'});
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .ts-forgot {
    height: 100%;
    background-color: #ffffff;
  }
</style>
